﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace Bank_database_system.业务部
{
    public partial class 交易记录查询c : UserControl
    {
        public event EventHandler ButtonBack;
        public 交易记录查询c()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
        private void button8_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            ButtonBack?.Invoke(this, EventArgs.Empty);
        }

        public void CardID_Set(string card, string acord, string id, string time, string describe, string amount, string state)
        {
            textBox5.Text = card;
            textBox6.Text = state;
            textBox1.Text = id;
            textBox2.Text = time;
            textBox3.Text = describe;
            textBox4.Text = amount;
            textBox7.Text = acord;
            if (textBox6.Text == "转账中")
            {
                button9.Visible = true;
            }
            else
                button9.Visible = false;
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            if (textBox6.Text == "转账中")
                button9.Visible = true;
            else
                button9.Visible = false;
        }

        private void button9_Click(object sender, EventArgs e)
        {

            if (textBox6.Text == "转账中")
            {
                DialogResult result = MessageBox.Show("请确认是否撤销转账。", "确认保存", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    //撤销过程
                    string describe = "";
                    string hostName = Dns.GetHostName(); // 获取主机名
                    IPAddress[] ipAddresses = Dns.GetHostAddresses(hostName); // 获取本机的IP地址

                    // 过滤出IPv4地址
                    IPAddress ipv4 = ipAddresses.FirstOrDefault(ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
                    if (ipv4 == null)
                    {
                        describe = "获取IP地址出现错误";
                        goto error;
                    }
                    string ip = ipv4.ToString();
                    using (输入密码 p = new 输入密码(textBox5.Text))
                    {
                        DialogResult q = p.ShowDialog();
                        if (q == DialogResult.OK)
                        {
                            MessageBox.Show(Transfer.CancleBusiness(textBox5.Text, textBox1.Text, ip, "2252721"));
                        }
                        else if (q == DialogResult.No)
                        {
                            describe = "密码错误";
                            goto error;
                        }
                    }
                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox6.Text = "";
                    textBox7.Text = "";
                    ButtonBack?.Invoke(this, EventArgs.Empty);
                    return;

                error:
                    MessageBox.Show(describe, "出现错误");
                    return;
                }
            }
        }

    }
}
